﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SweeperPrototype.Business.Fields;
using SweeperPrototype.Objects;

namespace SweeperPrototype.Business.Plumbing
{
    public interface IExposureMappingSource
    {
        List<ExposureMappingSubscription> FetchExposureMappings(ExposureRIC ric);
    }

    public class MockExposureMappingSource : IExposureMappingSource
    {
        private Dictionary<ExposureRIC, List<ExposureMappingSubscription>> m_Lookup;

        public MockExposureMappingSource()
        {
            m_Lookup = new Dictionary<ExposureRIC, List<ExposureMappingSubscription>>();
        }

        public List<ExposureMappingSubscription> FetchExposureMappings( ExposureRIC ric )
        {
            Random r = new Random();

            List<ExposureMappingSubscription> list;
            if( m_Lookup.TryGetValue( ric, out list ) == false )
            {
                list = new List<ExposureMappingSubscription>();
                int total = r.Next(2, 10);
                for( int i=0 ; i < total ; i++ )
                {
                    ExposureMappingSubscription mapping 
                        = new ExposureMappingSubscription( ric, new EffectiveRIC( ric.Value + i.ToString() ) );

                    ExposureMappingSubscription.ExposureMappingUpdate update = new ExposureMappingSubscription.ExposureMappingUpdate( new Multiplier(1), new Timestamp( DateTime.Now ) );
                    mapping.Update( update );

                    list.Add( mapping );
                }
                m_Lookup.Add( ric, list);
            }

            return list;

        }
    }
}
